<?php
 require_once 'DB.class.php';  
   
 class User {  
   
     public $memid;  
     public $username;  
     public $hashedPassword;  
     public $firstname;  
     public $lastname; 
     public $country_id;
     public $isadmin;


     //Constructor is called whenever a new object is created.  
     //Takes an associative array with the DB row as an argument.  
     function __construct($data) {  
         $this->memid = (isset($data['memid'])) ? $data['memid'] : "";  
         $this->username = (isset($data['email'])) ? $data['email'] : "";  
         $this->hashedPassword = (isset($data['password'])) ? $data['password'] : "";  
         $this->firstname = (isset($data['firstname'])) ? $data['firstname'] : "";  
         $this->lastname = (isset($data['lastname'])) ? $data['lastname'] : "";
         $this->country_id = (isset($data['country_id'])) ? $data['country_id'] : "";
         $this->isadmin = (isset($data['isadmin'])) ? $data['isadmin'] : 0;
         
     }  
   
     public function save($isNewUser = false) {  
         //create a new database object.  
         $db = new DBBase();  
   
         //if the user is already registered and we're  
         //just updating their info.  
         if(!$isNewUser) {  
			
             //set the data array  
             $data = array(  
                 "email" => "'$this->username'",  
                 "password" => "'$this->hashedPassword'",  
                // "email" => "'$this->email'"  
             );  
   
             //update the row in the database  
             $db->update($data, 'tblmember', 'memid = '.$this->id); 
			 
         }else { 
         //if the user is being registered for the first time. 
             $data = array( 
                 "email" => "'$this->username'", 
                 "password" => "'$this->hashedPassword'", 
                 "firstname" => "'$this->firstname'", 
                 "lastname" => "'$this->lastname'",          
                 "country_id" => "'$this->country_id'",
                 "register_date" => "'".date("Y-m-d H:i:s",time())."'"
             );  
   
             $this->memid = $db->insert($data, 'tblmember');    
         }  
         return true;  
     }  
     
     //change pass
     public function changePass()
     {
         $db = new DBBase();
         $data = array(  
            "memid" => "$this->memid",  
            "password" => "'$this->hashedPassword'");
         $db->update($data, 'tblmember', 'memid = '.$this->memid);
          
     }
   
 }  
 
 ?>  